// .txt

beginzonescript;

variables;

short crime_tolerance = 3;
short last_abil;
short i;
short hostile_ch = 0;

body;

beginstate INIT_STATE;
	sf(73,0,1);
	
	set_obj_act_at_dist(40,1);
	set_obj_act_at_dist(41,1);
	set_obj_act_at_dist(42,1);
	set_obj_act_at_dist(43,1);
	
	set_name(8,"Sergeant Farivar");
	set_name(21,"Workshop Researcher");
	set_name(22,"Workshop Researcher");
	set_name(23,"Artisan Cyrus");


	add_range_to_group(9,15,1);
	set_name(1001,"Servile Worker");
	set_courage(1001,0);

	add_range_to_group(24,28,2);
	add_range_to_group(29,33,3);
	add_range_to_group(34,38,4);
	add_range_to_group(39,43,5);
	
	add_range_to_group(44,47,6);
	
	if (get_sdf(73,7) > 0) {
		make_zone_hostile();
		}

	last_abil = get_current_tick();
	
	set_crime_tolerance(crime_tolerance);
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	// clear zone?
	//if ((zone_clear(ME) == FALSE) && (get_flag(,) > 0)) {
		//print_str_color("",2);
		//clear_zone(ME);	
		//}
		
	if ((get_crime_level() >= crime_tolerance) && (get_sdf(73,7) == 0)) {
		make_zone_hostile();
		set_flag(73,7,1);
		}

	if (gf(73,13) >= 4)
		sf(73,1,2);
		
	if ((hostile_ch == 0) && (gf(73,7) > 0)) {
		give_object_message(40,DOOR_OPEN_MESSAGE);
		give_object_message(41,DOOR_OPEN_MESSAGE);
		give_object_message(42,DOOR_OPEN_MESSAGE);
		give_object_message(43,DOOR_OPEN_MESSAGE);
		set_attitude(1002,10);
		set_attitude(1003,10);
		set_attitude(1004,10);
		set_attitude(1005,10);
		set_act_at_dist(1002,1);
		set_act_at_dist(1003,1);
		set_act_at_dist(1004,1);
		set_act_at_dist(1005,1);
		}
		
	 if (gf(73,7) == 0) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(9 + get_ran(1,0,6),"Cough.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(9 + get_ran(1,0,6),"Cough. Cough.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(9 + get_ran(1,0,6),"Must get.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(9 + get_ran(1,0,6),"Must hurry.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(23,"Where's the ore?");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(23,"Crystals for polishing.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(23,"Caustics need boiling.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(23,"I'm busy.");
		if ((get_ran(1,0,100) < 20) && (gf(73,12) == 0))
			give_char_text_bubble(8,"You need permission to enter.");
		if ((get_ran(1,0,100) < 20) && (gf(73,12) > 0))
			give_char_text_bubble(8,"You may pass.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(49,"Stay back from the vats.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(49,"Don't distract me.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(49,"This part is delicate.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(49,"Careful ...");
		}
	
	if (((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_group()) && (tick_difference(last_abil,get_current_tick()) > 2))) {
		last_abil = get_current_tick();
		
		if (gf(73,14) > 0) {
			inc_flag(73,14,-1);
			if (gf(73,14) > 0)
				print_str_color("Tick.",3);
				else {
					print_str_color("The western alcove fills with fire.",3);
					nav_point_damage_party(1,0,5,300,1);
					damage_char(1006,1000 + get_ran(1,0,500),1);
					play_sound(117);
					}
			}
		}
break;

beginstate 10;
	set_terrain_string_range("The sign says - First Aid Station.",3);
	break;

//	print_str("");
//	set_terrain_string_range(".",3);
//	set_terrain_string_range("The sign says - .",3);
